<?php 
/**
 * 用户登录管理模型
 */
class UserModel extends Model{
    public $table = 'user';
    
    public $auto = array();
    
    public $validate = array(
		array('username','nonull','用户名不能为空',2,3),
		array('password','nonull','密码不能为空',2,3),
		array('code','nonull','验证码不能为空',2,3),
	);
    
    /**
	 *验证登陆 
	 */
	public function vLogin(){
	 	if(!$this->create()) return false;
		//判断验证码是否正确
	    $code = strtoupper($_POST['code']);
		if($code != $_SESSION['code']){
			$this->error = '验证码错误';
			return false;
		}
		//判断用户名和密码是否正确
		$username = $_POST['username'];
		$password = md5($_POST['password']);
		$userInfo = $this->where("username='{$username}' OR nickname='{$username}'")->find();
		if(!$userInfo || $password != $userInfo['password']){
			$this->error = '用户名或密码错误';
			return false;
		}
		//判断用户是否被锁定
		if($userInfo['is_Lock']){
			$this->error = '您已经被锁定，请联系管理员';
			return false;
		}
		return $userInfo;
	}
	 
	public function isAdmin($username){
	    $isAdmin = $this->field('is_Admin')->where("username='{$username}'")->find();
		return $isAdmin['is_Admin'];
	} 
	 
	 
	 
	 
	 
	
 }
 
 
 






















 ?>